package com.firexxx.common.event;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.lang.NonNull;

/**
 * Created by mmxu6 on 2019-09-01.
 */
@Slf4j
public class EventPublisher implements ApplicationEventPublisherAware {
    private static ApplicationEventPublisher publisher;

    @Override
    public void setApplicationEventPublisher(@NonNull ApplicationEventPublisher applicationEventPublisher) {
        publisher = applicationEventPublisher;
    }

    public static void publishEvent(Event event) {
        log.info("{}, publish event: {}", event.getEventId(), event.getClass().getSimpleName());

        publisher.publishEvent(event);
    }
}
